const getters = {
  sidebar: state => state.app.sidebar,
  device: state => state.app.device,
  token: state => state.user.token,
  avatar: state => state.user.avatar,
  logo: state => state.app.logo,
  name: state => state.user.username,
  account: state => state.user.account,
  roles: state => state.user.roles,
  // isAdmin: (state) => {
  //   let bol = false
  //   state.user.roles.forEach(item => {
  //     if (item === 'admin') {
  //       bol = true
  //       return false
  //     }
  //   })
  //   return bol
  // },
  activeRoute: state => state.app.activeRoute,
  permission_routers: state => state.permission.routers,
  addRouters: state => state.permission.addRouters,
  userPageAuth: state => {
    let authority = state.user.authority
    let dic = {
      user: 'userinfo',
      userAuthority: 'auth',
      systemConfig: 'systemconfig',
      vehicleMileageWarnConfig: 'carmileageconfig',
      vehicleTimeWarnConfig: 'cartimeconfig',
      empWarnConfig: 'personconfig',
    }
    let auth = {
      userinfo: false,
      auth: false,
      systemconfig: false,
      carmileageconfig: false,
      cartimeconfig: false,
      personconfig: false
    }
    // 超级管理员返回全部权限
    if (state.user.supperAdmin) {
      return {
        userinfo: true,
        auth: true,
        systemconfig: true,
        carmileageconfig: true,
        cartimeconfig: true,
        personconfig: true
      }
    }
    let dicArr = ['user','userAuthority','systemConfig','vehicleTimeWarnConfig','vehicleTimeWarnConfig','empWarnConfig']
    authority.forEach(item => {
      let url = item.menuUrl
      if (dic.hasOwnProperty(url)) {
        auth[dic[url]] = item.authorityAll
      }
    })
    return auth
  },
  userAuth: state => {
    let authority = state.user.authority
    let dic = {
      vehicleBasicInfo: 'carinfo',
      deptEmpInfo: 'staffinfo',
      vehicleCheckEvaluate: 'checkjudge',
      vehicleRepairRecord: 'carMaintenance',
      goodsOutStorehouse: 'goodsout',
      goodsIntoStorehouse: 'goodsin',
      goodsCheck: 'goodscheck',
      monthDriveMileageCost: 'monthDriveMileageCost',
      warnDetails: 'details',
    }
    let authExmp = {
      authorityAdd:false,
      authorityDelete:false,
      authorityDown:false,
      authorityExport:false,
      authorityImport:false,
      authoritySearch:false,
      authorityUpdate:false,
      authorityUpload:false,
    }
    let auth = {
      carinfo: {...authExmp},
      staffinfo: {...authExmp},
      checkjudge: {...authExmp},
      carMaintenance: {...authExmp},
      goodsout: {...authExmp},
      goodsin: {...authExmp},
      goodscheck: {...authExmp},
      monthDriveMileageCost: {...authExmp},
      details: {...authExmp},
    }
    // 超级管理员返回全部权限
    if (state.user.supperAdmin) {
      authExmp = {
        authorityAdd:true,
        authorityDelete:true,
        authorityDown:true,
        authorityExport:true,
        authorityImport:true,
        authoritySearch:true,
        authorityUpdate:true,
        authorityUpload:true,
      }
      return {
        carinfo: {...authExmp},
        staffinfo: {...authExmp},
        checkjudge: {...authExmp},
        carMaintenance: {...authExmp},
        goodsout: {...authExmp},
        goodsin: {...authExmp},
        goodscheck: {...authExmp},
        monthDriveMileageCost: {...authExmp},
        details: {...authExmp},
      }
    }
    authority.forEach(item => {
      let url = item.menuUrl
      if (dic.hasOwnProperty(url)) {
        auth[dic[url]] = {
          authorityAdd:item.authorityAdd,
          authorityDelete:item.authorityDelete,
          authorityDown:item.authorityDown,
          authorityExport:item.authorityExport,
          authorityImport:item.authorityImport,
          authoritySearch:item.authoritySearch,
          authorityUpdate:item.authorityUpdate,
          authorityUpload:item.authorityUpload,
        }
      }
    })
    return auth
  },
  pageAuth(state, getter) {
    if (getter.userAuth.hasOwnProperty(state.app.activeRoute)) {
      return getter.userAuth[state.app.activeRoute]
    } else {
      return {
        authorityAdd:true,
        authorityDelete:true,
        authorityDown:true,
        authorityExport:true,
        authorityImport:true,
        authoritySearch:true,
        authorityUpdate:true,
        authorityUpload:true,
      }
    }
  },
}
export default getters
